ifeq "$(SCOE_BASE)" ""
force:: ;
% : force
	@ echo ERROR: need a definition for SCOE_BASE
	@ exit 1
endif

ifeq "$(PLATFORM)" ""
force:: ;
% : force
	@ echo ERROR: need a definition for PLATFORM
	@ exit 1
endif
include $(SCOE_BASE)/bin/commonDefinitions.mak
include $(SCOE_BASE)/platforms/$(PLATFORM)/platformDefinitions.mak

export SYSTEM_BASE  := $(SCOE_BASE)/Examples/MotorTestDemo

OUTPUTDIR=MotorController_Bank
OUTPUTDIR_DEBUG := $(OUTPUTDIR)_Debug

TARGET=$(OUTPUTDIR)/MotorController
APPLICATION_ENTRY_POINT := motorControllerStart

CFLAGS=\
       $(CFLAGS_DEFAULT_INCLUDE) \
       -I$(SCOE_BASE)\examples\MotorTestDemo\Applications\MotorController/ \
       -DENTRY_POINT=$(APPLICATION_ENTRY_POINT)
    
LINK_FLAGS_RELEASE = -lpthread -lrt  $(SSLINTERFACE_LIB_RELEASE) $(AUTOTEST_LIB_RELEASE) -Wl,-T $(PLATFORM_LDS)

LINK_FLAGS_DEBUG = -lpthread -lrt  $(SSLINTERFACE_LIB_DEBUG) $(AUTOTEST_LIB_DEBUG) -Wl,-T $(PLATFORM_LDS)

SOURCE=Applications/MotorController/MotorController.c \
		   Applications/MotorController/AswTest.c      \
		   Applications/MotorController/calPrms.c      \
		   Applications/MotorController/monPrms.c      \
		   Applications/MotorController/rtGetInf.c     \
		   Applications/MotorController/rtGetNaN.c     \
		   Applications/MotorController/rt_nonfinite.c \
                   Applications/MotorController/parseMessage.c \
       $(MAIN_SOURCE) \
       $(SCOE_BASE)/bin/usrAppInit.c

.PHONY: all clean makeDirectories release debug

all: clean release


release:
	-if not exist $(OUTPUTDIR)	$(MKDIR) $(OUTPUTDIR)
	$(CC) $(CFLAGS) -Wall $(SOURCE) -o $(TARGET) $(LINK_FLAGS_RELEASE)
	$(ADECONFIGGEN) ConfigData/Module.xml /o=$(OUTPUTDIR)/PartitionConfig.cfg /es=ConfigData/scoeA664p7EndSystemConfig/GPM1.txt
	
debug: OUTPUTDIR:=$(OUTPUTDIR_DEBUG)
debug:
	-if not exist $(OUTPUTDIR)	$(MKDIR) $(OUTPUTDIR)
	$(CC) $(GCC_DEBUG_FLAGS) -DLC_DEBUG_MODE $(CFLAGS) -Wall $(SOURCE) -o $(TARGET) $(LINK_FLAGS_DEBUG)
	$(ADECONFIGGEN) ConfigData/Module.xml /o=$(OUTPUTDIR)/PartitionConfig.cfg /es=ConfigData/scoeA664p7EndSystemConfig/GPM1.txt

clean: 
	-$(RMDIR) $(RMDIR_FLAGS) $(OUTPUTDIR)
	-$(RMDIR) $(RMDIR_FLAGS) $(OUTPUTDIR_DEBUG)
